package ListNodeSecond.SwordOffer;

import java.util.ArrayList;
import java.util.List;

public class IsPalindromeList {
    public boolean isPalindrome(ListNode head) {

        if (head == null) {
            return true;
        }
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        int i = 0;
        int j = list.size() - 1;
        while (i < j) {
            if(list.get(i)!=list.get(j)){
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
}
